/**
 * Created by gaoyj on 2018/6/28.
 */
window.onload = function (ev) {
    topbar.hide();
};

$('#dataTable').bootstrapTable({
    url: '/productPrice/findModelPrice',
    height: $(window).height() - 200,
    pageSize: 30,
    pageList: [30, 50, 100],
    clickToSelect: true,
    uniqueId: 'id',
    queryParamsType: '',
    sidePagination: 'server',
    responseHandler: function (res) {
        return {
            "rows": res
        };
    },
    columns: [
        {
            checkbox: true
        },
        {
            align: 'center',
            formatter: function (v, row, index) {
                return index + 1
            }
        }, {
            align: 'center',
            field: 'modelName',
            title: '模板名称'
        },  {
            align: 'center',
            field: 'remark',
            title: '备注'
        }
    ],
});
function addModelFun(v) {
    $("#addModelLabel").attr("msg", v)
    $("#userKey").attr("readonly", "false");
    if (v == 1) {
        $("#addModelLabel").text("添加密价模板");
        $("#addModelPriceForm input,#addUserForm textarea,#addUserForm select").val("");
    } else {
        $("#addModelLabel").text("修改密价模板");
        var rows = $('#dataTable').bootstrapTable("getSelections");
        if (rows == null || rows.length === 0) {
            layer.msg("请选择要操作的数据");
            return;
        }
        var row = rows[0];
        $("#hidId").val(row.id);
        $("#modelName").val(row.modelName);
        $("#remark").val(row.remark);
    }
    $("#addModelModal").modal({backdrop: 'static', keyboard: false});
}
$("#addModelSubmit").click(function () {
    var msg = $("#addModelLabel").attr("msg");
    var url;
    if (msg == 1) {
        url = "/productPrice/addPriceModel"
    } else {
        url = "/productPrice/modifyPriceModel"
    }
    $.ajax({
        type: "post",
        url: url,
        data: $("#addModelPriceForm").serialize(),
        dataType: "json",
        async: false,
        cache: false,
        success: function (data) {
            if(data.success){
                $("#dataTable").bootstrapTable("refresh");
                $("#addModelModal").modal("hide");
                layer.msg('操作成功');
            } else {
                layer.msg(data.message)
            }
        }
    });
})
$("#search").click(function () {
    $("#dataTable").bootstrapTable("refresh");
});
